package com.example.oa;

import javax.management.relation.Role;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @author 23333
 */
public class FilterTest implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        int roleId;
        if(httpServletRequest.getSession().getAttribute("roleId")!=null){
            roleId = (int) httpServletRequest.getSession().getAttribute("roleId");
            if(roleId != 1){
                httpServletRequest.setAttribute("message","您没有访问权限，请重新登陆！");
                httpServletRequest.getRequestDispatcher("/OA/index.jsp").forward(request,response);
            }
        }


        chain.doFilter(request,response);
    }
}
